package cn.kgc.controller;

import cn.kgc.pojo.SmbmsUser;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;


@Controller
@RequestMapping("/hello")
public class HelloController {

    private Logger logger = Logger.getLogger(HelloController.class.getName());
    @RequestMapping(value = "/index",method = RequestMethod.GET)
    public String index(@RequestParam(value ="username",required = false) String username,
                        @RequestParam(value ="userPwd",required = false) String userPwd){
        logger.info("username ="+username);
        logger.info("userPwd ="+userPwd);
        return "index";
    }

    @RequestMapping(value = "/index1",method = RequestMethod.POST)
    public String index1(SmbmsUser smbmsUser){
        logger.info((smbmsUser.toString()));
        return "index";
    }
    @RequestMapping(value = "/index2",method = RequestMethod.GET)
    public String index2(Model model){
        model.addAttribute("name","王昌盛");
        SmbmsUser smbmsUser = new SmbmsUser();
        smbmsUser.setId(1);
        smbmsUser.setUserName("王昌盛");
        model.addAttribute("smbmsUser",smbmsUser);

        SmbmsUser u1 = new SmbmsUser();
        u1.setId(1);
        u1.setUserName("王昌盛");
        SmbmsUser u2 = new SmbmsUser();
        u2.setId(2);
        u2.setUserName("赵纵宇");
        SmbmsUser u3 = new SmbmsUser();
        u3.setId(3);
        u3.setUserName("黄少坤");
        List<SmbmsUser> list = new ArrayList<>();
        list.add(u1);
        list.add(u2);
        list.add(u3);
        model.addAttribute("userlist",list);
        return "index";
    }
}
